<template>
  <el-aside style="min-height: 100%; background-color: #545c64; overflow: hidden">
    <el-menu
      class="el-menu-vertical-demo"
      router
      :default-openeds="['1','2']"
      default-active="/"
      @open="handleOpen"
      @close="handleClose"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#409EFF"
    >
      <el-submenu index="1">
        <template slot="title">
          <i class="el-icon-document"></i>
          <span>主页</span>
        </template>
      </el-submenu>
      <el-submenu index="2">
        <template slot="title">
          <i class="el-icon-setting"></i>
          <span>Properties</span>
        </template>
        <el-menu-item-group>
          <el-menu-item v-for="(item, index) in list" :key="index" @click="handleClick(item,index)">{{item}}</el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </el-aside>
</template>

<script>
export default {
  name: "TheNav",

  data() {
    return {
      list: [
        "Commercial Building(47)",
        "Condo(2444)",
        "House(497)",
        "House with Pool(486)",
        "Land(105)",
        "Shop House(3)",
        "Town House(76)",
        "Villa(51)",
        "Villa with Pool(863)"
      ]
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClick(item,index){
      const q = item.split('(')[0]
      this.$http.post("/api/getList",{types:q}).then(({ data }) => {
        const res = data.list;
        this.$store.commit('LIST_MUTATION',res)
        this.$store.commit('TYPES_MUTATION',q)
      });
    }
  }
};
</script>

<style scoped lang="scss">
</style>
